import cv2
#读取图像
img = cv2.imread("../images/lena.png")
logo = cv2.imread("../images/hqyj_logo.png")
h, w, _ = logo.shape
#灰度化 二值化 白底黑字
logo_gray = cv2.cvtColor(logo, cv2.COLOR_BGR2GRAY)
_, logo_binary = cv2.threshold(
    logo_gray,
    70,
    255,
    cv2.THRESH_BINARY_INV
)
#进行位运算 彩底黑字
ROI = img[10:10+h, 10:10+w]
# cv2.imshow("ROI", ROI)
ROI_bitadd_logo = cv2.bitwise_and(
    ROI,
    ROI,
    mask=logo_binary
)

ROI_add_logo = cv2.add(
    logo,
    ROI_bitadd_logo
)
#替换到原图上
img[10:10+h, 10:10+w] = ROI_add_logo
cv2.imshow("image", img)
cv2.waitKey(0)